package com.example.demo.dao;

import com.example.demo.Enity.indexAll;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.util.ArrayList;

public interface IndexJpa extends JpaRepository<indexAll, Integer>, JpaSpecificationExecutor<indexAll> {

    @Query(nativeQuery = true, value = "select * from index_all where fen=?1")
    ArrayList<indexAll> find(String fen);

    //每上传一次活动活动数量加一
    @Modifying
    @Transactional
    @Query(nativeQuery = true, value = "update index_all set num=num+1 where category=?1")
    void addNum(String category);

    //每上传一次活动活动数量减一
    @Modifying
    @Transactional
    @Query(nativeQuery = true, value = "update index_all set num=num-1 where category=?1")
    void reduceNum(String category);

}
